package com.yishusmt.mobsmt.controller;

import com.yishusmt.mobsmt.check.DataCheck;
import com.yishusmt.mobsmt.dto.base.Result;
import com.yishusmt.mobsmt.dto.request.AddressReq;
import com.yishusmt.mobsmt.dto.request.OrderDetailsReq;
import com.yishusmt.mobsmt.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;

/**
 * 下单控制
 *
 * @author zhangyi
 * @date 2018/8/10 17:40
 */
@RestController
@Api("用户下单控制")
@RequestMapping("/order")
public class OrderManageController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     *
     * @return
     */
    @PostMapping("/placeAnOrder")
    @ApiOperation(value = "用户下单",httpMethod = "POST")
    public Result placeAnOrder(@RequestBody OrderDetailsReq orderDetailsReq){
        return orderService.placeAnOrder(orderDetailsReq);
    }

    /**
     * 查询用户订单详细信息
     *
     * @param orderId
     * @return
     */
    @GetMapping("/orderInfo/{orderId}")
    @ApiOperation(value = "查询用户订单详细信息",httpMethod = "GET")
    public Result orderInfo(@PathVariable("orderId") @NonNull Long orderId){
        DataCheck.isNull(orderId);
        System.out.println(orderService.orderInfo(orderId).toString());
        return orderService.orderInfo(orderId);
    }

    /**
     * 分类返回所有的订单列表
     *
     * @return
     */
    @GetMapping("/seek/phone/{phone}/{status}")
    @ApiOperation(value = "分类返回所有的订单列表",httpMethod = "GET")
    public Result ownOrderList(@PathVariable("status") @NonNull Integer status,
                               @PathVariable("phone") @NonNull String phone){
        DataCheck.isNull(status);
        DataCheck.isNull(phone);
        return orderService.ownOrderList(status,phone);
    }
}
